#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int mod = 1000000007;
using namespace std;

int N;
int G[22][22];
ll f[22][(1<<21)+5];

ll solve(){
    for(int j = 0;j<N;j++){
        if(G[0][j] == 1) f[0][1<<j] += 1;
    }
    for(int i = 1;i<N;i++){
        for(int j = 0;j<N;j++){
            if(G[i][j] == 1){
                for(int hs = 0;hs<(1<<N);hs++){
                    if(!(hs>>j & 1)) f[i][hs | (1<<j)] =  (f[i][hs | (1<<j)] + f[i-1][hs])%mod;
                }
            }
        }
    }
    return f[N-1][(1<<N)-1];
}
int main(){
    // debug;
    ios;

    cin>>N;
    for(int i = 0;i<N;i++){
        for(int j = 0;j<N;j++){
            cin>>G[i][j];
        }
    }

    cout<<solve()<<"\n";


    
    return 0;
}
